package com.exception;

import com.service.UserServiceImpl;

import java.util.Scanner;

/***
 * @ClassName: Test
 * @Description:
 * @Auther: 送一一块二向箔
 * @Date: 15:27 2022/1/27
 * @version : V1.0
 */
public class Test {

    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
/*        Test test = new Test();
        test.useGetAge();*/
        Class<?> string = Class.forName("com.service.UserServiceImpl");
        UserServiceImpl o = (UserServiceImpl)string.newInstance();
        o.speak();


    }


   void useGetAge(){
       try {
           while (true) {
               getAge();
           }
       } catch (MyException e) {
           e.printStackTrace();
       }
   }

    //创建一个方法并抛出自定义异常
    void getAge() throws MyException {
        System.out.println("请输入年龄（按回车结束）：");
        Scanner scanner = new Scanner(System.in);
            if (scanner.hasNextInt()) {
                int i = scanner.nextInt();
                if (i > 100) {
                    throw new MyException(i);
                }
                System.out.println("您输入的年龄是" + i);
            }

    }
}
